﻿using IHISCETeim.BLL;
using IHISCETeim.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using IHISCETeim.Library;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
namespace IHISCETeim.Web.AgentSys.VipMgr
{
    public partial class VIPCustomerEdit : AgentPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }
        protected override string DWZRef
        {
            get { return "VIPCustomerList"; }

        }


        protected int CustomerId
        {
            get {
                return GetRequestValue<int>("CustomerId", 0);
            }
        }

        private VIPCustomerInfo _vipObj = null;
        protected VIPCustomerInfo vipObj
        {
            get {
                if (_vipObj == null)
                    _vipObj = VIPCustomerController.GetList(CustomerId);

                return _vipObj;
            }
        }

        protected string GetAgentList(int userid)
        {
            StringBuilder sb = new StringBuilder();
            DataTable dt = OUserController.GetPagination("", "", 2, 1, 999999, " UserId DESC", ref TotalCount);
            foreach (DataRow dr in dt.Rows)
            {
                sb.AppendFormat("<option value=\"{0}\" {2}>{1}</option>", dr["UserId"], dr["RealName"], userid==Convert.ToInt32(dr["UserId"])?"selected":"");
            }
            return sb.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "edit")
            {
                add();//
            }
        }
        private void add()
        {
            if (base.User.UserType != 1)
                return;
            VIPCustomerInfo obj = Request.SerializableObject<VIPCustomerInfo>();
            obj.IsVIP = vipObj.IsVIP;
            obj.AgentName = OUserController.GetById(obj.UserId).RealName;
           
           

            int R = VIPCustomerController.Update(obj);
            switch (R)
            {
                case -1:
                    ErrorJson("修改VIP客户失败,一个身份证号码只能对应一个VIP客户,不能重复添加.");
                    break;
                case 0:
                    ErrorJson("修改VIP客户失败");
                    break;
                default:
                    SuccessJson("修改VIP客户成功", this.DWZRef);
                    break;
            }
        }
    }
}